define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chient/index/index' + location.search,
                    add_url: 'chient/index/add',
                    edit_url: 'chient/index/edit',
                    del_url: 'chient/index/del',
                    multi_url: 'chient/index/multi',
                    import_url: 'chient/index/import',
                    table: 'aa_client',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('茶楼名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'time', title: __('陌拜时间'), operate: false , formatter: Table.api.formatter.datetime},
                        {field: 'quyu_text', title: __('区域'), operate: false },
                        {field: 'quyu_id', title: __('销售'), searchList:$.getJSON("general/quyu/getallquyu"), formatter: Table.api.formatter.normal },
                        {field: 'address', title: __('地点'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'types', title: __('定位'), searchList: {"1":__('Types 1'),"0":__('Types 0')}, formatter: Table.api.formatter.normal},
                        {field: 'ctypes', title: __('类型'), searchList: {"1":__('Ctypes 1'),"2":__('Ctypes 2'),"3":__('Ctypes 3')}, formatter: Table.api.formatter.normal},
                        {field: 'wimages', title: __('报价单'), events: Table.api.events.images, formatter: Table.api.formatter.image, operate: false},
                        {field: 'c_name', title: __('C_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'c_mobile', title: __('C_mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'c_wx', title: __('C_wx'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'level', title: __('店面档次'), operate: false },
                        {field: 'shoper', title: __('店员数量'), operate: false },
                        {field: 'seat1', title: __('卡座数量'), operate: false },
                        {field: 'seat2', title: __('包间数量'), operate: false },
                        {field: 'month', title: __('月度用量'), operate: false },
                        {field: 'test', title: __('是否试用'), operate: false },
                        {field: 'testr', title: __('试用结果'), operate: false },
                        {field: 'rival_name', title: __('Rival_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'rival_desc', title: __('对手说明'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        // {field: 'ctypestime', title: __('Ctypestime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

                            buttons: [
                                {
                                    name: 'detail',
                                    text: __(''),
                                    title: __('设置状态'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa  fa-gear',
                                    url: 'chient/index/seting',
                                    callback: function (data) {
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __(''),
                                    title: __('访问信息'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'chient/index/logs',
                                    callback: function (data) {},
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }]

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        logs:function (){

            Table.api.init({
                extend: {
                    index_url: 'chient/index/logsajax',
                    table: ''
                }
            });

            var tableb = $("#table1");

            var id=$("#ids").val();

            // 初始化表格
            tableb.bootstrapTable({
                url: 'chient/index/logsajax/ids/'+id,
                pk: 'id',
                sortName: 'id',
                type:'post',
                search: false,
                showSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID', operate: false},
                        {field: 'name', title: __('区域')},
                        {field: 'title', title: __('类型')},
                        {field: 'desc', title: __('说明')},
                        {field: 'time', title: __('操作时间')}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(tableb);



        },

        add: function () {
            Controller.api.bindevent();
        },

        seting: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },

    };
    return Controller;
});
